<template>
  <div class="chart" :class="{'active':isActive}" ref="chart" style="width:70%;height:300px;border-radius: 20px;" @mouseover="hover" @mouseleave="unhover"></div>
</template>

<script>
import * as echarts from "echarts";

export default {
    data() {
        return {
           isActive:false
        }
    },
    methods:{
        getEchart(){
            const chart = this.$refs.chart;
            if (chart) {
                const myChart = this.$echarts.init(chart)
            const option = {
                backgroundColor: 'rgba(34, 40, 87,0)',
    title:{
         text: '产出明细',
         left:'42%',
         top:'5%',
         textStyle:{
             color:'#fff',
             fontSize:'20'
         }
    },
	tooltip: { //提示框组件
		trigger: 'axis',
		formatter: '{b}<br />{a0}: {c0}<br />{a1}: {c1}',
		axisPointer: {
			type: 'shadow',
			label: {
				backgroundColor: '#6a7985'
			}
		},
		textStyle: {
			color: '#fff',
			fontStyle: 'normal',
			fontFamily: '微软雅黑',
			fontSize: 12,
		}
	},
	grid: {
		left: '5%',
		right: '5%',
		bottom: '10%',
		top:'20%',
	//	padding:'0 0 10 0',
		containLabel: true,
	},
    legend: {//图例组件，颜色和名字
        right:'10%',
		top:'10%',
		itemGap: 16,
		itemWidth: 18,
		itemHeight: 10,
        data:[{
            name:'计划产出',
            //icon:'image://../wwwroot/js/url2.png', //路径
        },
        {
            name:'实际产出',
        }],
        textStyle: {
			color: '#a8aab0',
			fontStyle: 'normal',
			fontFamily: '微软雅黑',
			fontSize: 12,            
        }
    },
	xAxis: [
		{
			type: 'category',
		//	boundaryGap: true,//坐标轴两边留白
			data: ['00:00', '02:00', '04:00','06:00','08:00','10:00','12:00','14:00','16:00', '18:00', '20:00','22:00','22:30','22:33','22:35','22:40'],
			axisLabel: { //坐标轴刻度标签的相关设置。
		//		interval: 0,//设置为 1，表示『隔一个标签显示一个标签』
			//	margin:15,
				textStyle: {
					color: '#078ceb',
					fontStyle: 'normal',
					fontFamily: '微软雅黑',
					fontSize: 12,
				},
				rotate:50,
			},
			axisTick:{//坐标轴刻度相关设置。
				show: false,
			},
			axisLine:{//坐标轴轴线相关设置
				lineStyle:{
					color:'#fff',
					opacity:0.2
				}
			},
			splitLine: { //坐标轴在 grid 区域中的分隔线。
				show: false,
			}
		}
	],
	yAxis: [
		{
			type: 'value',
			splitNumber: 5,
			axisLabel: {
				textStyle: {
					color: '#a8aab0',
					fontStyle: 'normal',
					fontFamily: '微软雅黑',
					fontSize: 12,
				}
			},
			axisLine:{
				show: false
			},
			axisTick:{
				show: false
			},
			splitLine: {
				show: true,
				lineStyle: {
					color: ['#fff'],
					opacity:0.06
				}
			}

		}
	],
    series : [
        {
            name:'计划产出',
            type:'bar',
            data:[10,15, 30, 45, 55, 60, 62, 80,80,62, 60, 55, 45, 30, 15, 10],
            barWidth: 10,
            barGap:0,//柱间距离
            // label: {//图形上的文本标签
            //     normal: {
            //       show: true,
            //       position: 'top',
            //       textStyle: {
            //           color: '#a8aab0',
            //           fontStyle: 'normal',
            //           fontFamily: '微软雅黑',
            //           fontSize: 12,   
            //       },
            //     },
            // },
          itemStyle: {
                normal: {
                    show: true,
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: '#5768EF'
                    }, {
                        offset: 1,
                        color: '#5768EF'
                    }]),
                    barBorderRadius: 50,
                    borderWidth: 0,
                }
            },
        },
        {
            name:'实际产出',
            type:'bar',
            data:[8,5, 25, 30, 35, 55, 62, 78,65,55, 60, 45, 42, 15, 12, 5],
            barWidth: 10,
            barGap:0,//柱间距离
            // label: {//图形上的文本标签
            //     normal: {
            //       show: true,
            //       position: 'top',
            //       textStyle: {
            //           color: '#a8aab0',
            //           fontStyle: 'normal',
            //           fontFamily: '微软雅黑',
            //           fontSize: 12,   
            //       },
            //     },
            // },
             itemStyle: {
                normal: {
                    show: true,
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: '#69CBF2'
                    }, {
                        offset: 1,
                        color: '#69CBF2'
                    }]),
                    barBorderRadius: 50,
                    borderWidth: 0,
                }
            },
        }
    ]
            }
            myChart.setOption(option)
            window.addEventListener('resize',()=>{
                myChart.resize()
            })
            }
         
        },
        autoResize() {
      this.$echarts.init(this.$refs.chart).resize()
    },
    hover(){
        this.isActive=true
        // alert(1)
    },
    unhover(){
        this.isActive=false

}
    },
    mounted(){
        this.getEchart()
    },
    watch:{
    '$store.state.app.sidebar.opened':{
        handler:function(){
          setTimeout(() => {
        this.autoResize()
         console.log('我更新了1111');
          }, 300);
        },
        deep:true
   
    }
  }
}
</script>

<style scoped>
.chart{
    padding: 10px;
  background: rgba(34, 40, 87,.4);
    
  border-radius: 20px !important;
    transition: all .5s;
}
.active{
    transform: translateY(-10px) translateX(-10px);
  box-shadow: 8px 8px 5px rgb(50, 104, 165);

}
</style>